Fold (Unix)
   HOME

TheInfoList



OR:

fold is a
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, ...
command used for making a file with long lines more readable on a limited width
computer terminal A computer terminal is an electronic or electromechanical hardware device that can be used for entering data into, and transcribing data from, a computer or a computing system. The teletype was an example of an early-day hard-copy terminal and ...
by performing a line wrap. Most
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, ...
terminals have a default screen width of 80, and therefore reading files with long lines could get annoying. The fold command puts a
line feed Newline (frequently called line ending, end of line (EOL), next line (NEL) or line break) is a control character or sequence of control characters in character encoding specifications such as ASCII, EBCDIC, Unicode, etc. This character, or ...
every X characters if it does not reach a new line before that point. If the -w argument is set, the fold command allows the user to set the maximum length of a line.


History

is part of the
X/Open X/Open group (also known as the Open Group for Unix Systems and incorporated in 1987 as X/Open Company, Ltd.) was a consortium founded by several European UNIX systems manufacturers in 1984 to identify and promote open standards in the field of info ...
Portability Guide since issue 4 of 1992. It was inherited into the first version of POSIX.1 and the Single Unix Specification. It first appeared in 1BSD of 1977. The version of fold bundled in
GNU GNU () is an extensive collection of free software (383 packages as of January 2022), which can be used as an operating system or can be used in parts with other operating systems. The use of the completed GNU tools led to the family of operat ...
coreutils The GNU Core Utilities or coreutils is a package of GNU software containing implementations for many of the basic tools, such as cat, ls, and rm, which are used on Unix-like operating systems. In September 2002, the ''GNU coreutils'' were cr ...
was written by David MacKenzie. The command is available as a separate package for
Microsoft Windows Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for ...
as part of the
UnxUtils UnxUtils is a collection of ports of common GNU Unix-like utilities to native Win32, with executables only depending on the Microsoft C- runtime msvcrt.dll. The collection was last updated externally on April 15, 2003, by Karl M. Syring. The mo ...
collection of
native Native may refer to: People * Jus soli, citizenship by right of birth * Indigenous peoples, peoples with a set of specific rights based on their historical ties to a particular territory ** Native Americans (disambiguation) In arts and entert ...
Win32 The Windows API, informally WinAPI, is Microsoft's core set of application programming interfaces (APIs) available in the Microsoft Windows operating systems. The name Windows API collectively refers to several different platform implementations th ...
ports A port is a maritime facility comprising one or more wharves or loading areas, where ships load and discharge cargo and passengers. Although usually situated on a sea coast or estuary, ports can also be found far inland, such as H ...
of common GNU Unix-like utilities.


Example

As a usage example, to fold a file named file.txt to have a maximum of 50 characters per line, one could run the following command: fold -w 50 file.txt *file.txt:
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur dignissim
venenatis pede. Quisque dui dui, ultricies ut, facilisis non, pulvinar non,
purus. Duis quis arcu a purus volutpat iaculis. Morbi id dui in diam ornare
dictum. Praesent consectetuer vehicula ipsum. Praesent tortor massa, congue et,
ornare in, posuere eget, pede. 

Vivamus rhoncus. Quisque lacus. In hac habitasse platea dictumst. Nullam mauris
tellus, sollicitudin non, semper eget, sodales non, pede. Phasellus varius
ullamcorper libero. Fusce ipsum lorem, iaculis nec, vulputate vitae, suscipit
vel, tortor. Cras varius.

Nullam fringilla pellentesque orci. Nulla eu ante pulvinar velit rhoncus
lacinia. Morbi fringilla lacus quis arcu. Vestibulum sem quam, dapibus in,
fringilla ut, venenatis ut, neque.
*output:
Lorem ipsum dolor sit amet, consectetuer adipiscin
g elit. Curabitur dignissim
venenatis pede. Quisque dui dui, ultricies ut, fac
ilisis non, pulvinar non,
purus. Duis quis arcu a purus volutpat iaculis. Mo
rbi id dui in diam ornare
dictum. Praesent consectetuer vehicula ipsum. Prae
sent tortor massa, congue et,
ornare in, posuere eget, pede. 

Vivamus rhoncus. Quisque lacus. In hac habitasse p
latea dictumst. Nullam mauris
tellus, sollicitudin non, semper eget, sodales non
, pede. Phasellus varius
ullamcorper libero. Fusce ipsum lorem, iaculis nec
, vulputate vitae, suscipit
vel, tortor. Cras varius.

Nullam fringilla pellentesque orci. Nulla eu ante 
pulvinar velit rhoncus
lacinia. Morbi fringilla lacus quis arcu. Vestibul
um sem quam, dapibus in,
fringilla ut, venenatis ut, neque.


See also

*
coreutils The GNU Core Utilities or coreutils is a package of GNU software containing implementations for many of the basic tools, such as cat, ls, and rm, which are used on Unix-like operating systems. In September 2002, the ''GNU coreutils'' were cr ...
* fmt (Unix) *
Par (command) The computer program par is a text formatting utility for Unix and Unix-like operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common daemon (computing), services for ...
*
List of Unix commands This is a list of Unix commands as specified by IEEE Std 1003.1-2008, which is part of the Single UNIX Specification (SUS). These commands can be found on Unix operating systems and most Unix-like operating systems. List See also * List of G ...
* Text mode#PC common text modes


References


External links

* * Unix text processing utilities Unix SUS2008 utilities {{unix-stub